// 页面渲染

var id = $.getUrlParam('id')

$.ajax({
    type: "GET",
	url: "/info/update",
	data:{'id':id},
	dataType: "json",
	success: function (result) {
	       	if(result.status){

				var data = result.data

				$('#title').val(data.title);

				$('#tag_name').val(data.tag_name);

				$('#cover_img').attr('src', data.cover_img);

				$('#location').val(data.location);

				$('#description').val(data.description);

				$('#weight').val(data.weight);

				if(data.share_img)
				{
					$.each(data.share_img,function(n,value) {   
						$('#info_share_img').append("<img src="+value.info_share_img+">");	 	
	           		}); 
				}

				if(data.status == 0)
				{
					$('#delete').attr('disabled', 'disabled');
					$('#delete').html('已删除')

					$('#weight-div').css('display', 'none')
				}

			}
	},
	error: function (XMLHttpRequest, textStatus, errorThrown) {
	        alert(errorThrown);
	},
	async: false
});


$('#info_share_img img').css('display', 'block')

$('#delete').click(function(){

	

	$.post("/info/delete",
			{'id':id},
			function(result){
	            if(result.status == true){
	              
	                // $(".head-title").append($.successAlert(result.msg+" 3秒后自动跳转"));
	             	$.successAlert(result.msg);

					setTimeout(function (){window.location.href='/info'}, 3000)
	            }else{
	            	$.errorAlert(result.msg);

					return false;	
	            }
	},"json");

})


$('#submit').click(function(){

	var weight =  $('#weight').val();

	$.post("/info/update",
			{'id':id, 'weight':weight},
			function(result){
	            if(result.status == true){
	              
	                $.successAlert(result.msg);
					setTimeout(function (){window.location.href='/info'}, 3000)
	            }else{
	            	$.errorAlert(reset.msg);

					return false;	
	            }
	},"json");

})